package com.parktech.sun.web.controller;

import com.parktech.sun.domain.repository.Page;
import com.parktech.sun.domain.service.unionnews.UnionNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * User: Think                                            s
 * Date: 11-1-20
 * Time: 下午10:48
 */
@Controller
@RequestMapping("/unionnews")
public class UnionNewsViewController extends BaseViewController {

    private int pageSize = 4;

    private UnionNewsService unionNewsService;

    @Autowired
    public UnionNewsViewController(UnionNewsService unionNewsService) {
        this.unionNewsService = unionNewsService;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    @RequestMapping("/pages/{pageNo}")
    public String viewPage(@PathVariable int pageNo, Model model) {
        Page page = new Page(pageSize, pageNo);
        model.addAttribute(unionNewsService.page(page));
        return "unionNews";
    }

    @RequestMapping("/{unionNewsId}")
    public String viewDetail(@PathVariable Long unionNewsId, Model model) {
        model.addAttribute(unionNewsService.getById(unionNewsId));
        return "unionNewsDetail";
    }
}
